package com.cndemoz.aformchange.demo;

import com.cndemoz.aformchange.FormHandler;
import com.cndemoz.aformchange.ViewsUtil;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView tvChange;
    private EditText editText1;
    private EditText editText2;

    private Button button1;

    private FormHandler formHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	tvChange = (TextView) findViewById(R.id.tv_change);
	editText1 = (EditText) findViewById(R.id.editText1);
	editText2 = (EditText) findViewById(R.id.editText2);
	button1 = (Button) findViewById(R.id.button1);
	
	formHandler = new FormHandler(ViewsUtil.getAllEditTexts(this));
	//初始化数据和文本改变监听器，必须放在赋值之后
	formHandler.initTextAndTextChangedListener();

	button1.setOnClickListener(new OnClickListener() {

	    @Override
	    public void onClick(View v) {
		if (formHandler.isTextChange()) {//isTextChange判断是否改变
		    tvChange.setText("Change");
		} else {
		    tvChange.setText("Not Change");
		}
	    }
	});

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.main, menu);
	return true;
    }

}
